cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/Table1.log", replace

clear all
set more off

matrix Results = J(33, 9, -9)

use "RawData/GallupDataBJPS.dta", clear
// Drops Unrepresentative Series
drop if drops == "All" | regexm(drops, "Party")
// Drops Obs. w/o Gender
drop if female < 0
// Drops Obs. w/o Weights
drop if final_weight < 0
// Drops Obs. w/o Dem., Ind., or Rep.
keep if party == -1 | party == 0 | party == 1
// Drops Obs. w/o Education
drop if education < 0
// Drops Phone Surveys
keep if survey == 1

// Sets the Survey Date as the Mid-Point in Field
gen middle_date = .
replace middle_date = floor((start_date + end_date) / 2)
sort middle_date

gen year = -9
replace year = year(middle_date)  

// Codes Dem. as 0, Ind. as 1/2, and Rep. as 1
gen partisan = 0 if party == -1
replace partisan = 1 if party == 1
replace partisan = .5 if party == 0

// College Gradudates
gen college = (education == 5)

gen female_college = female * (college == 1)

forvalues i = 1953(4)1993 {
local j = 1 + (3 * (`i' - 1953) / 4)
areg partisan female college female_college [aweight = final_weight] /*
*/  if year >= `i' & year <= `i' + 3, absorb(series) robust
mat A = e(V)
matrix Results[`j', 1] = _b[female_college] 
matrix Results[`j' + 1, 1] = -_se[female_college] 
matrix Results[`j' + 2, 1] = e(N)
}

drop if black == -99 | black == -9
drop if state == -99 | state == -9
gen newengland = (state >= 11 & state <= 16)
gen midatlanic = (state >= 21 & state <= 27)
gen central = (state >= 31 & state <= 48)
gen south = (state >= 51 & state <= 65)
gen mountain = (state >= 71 & state <= 78)

gen female_black = female * black
gen female_newengland = female * newengland
gen female_midatlanic = female * midatlanic
gen female_central = female * central
gen female_south = female * south
gen female_mountain = female * mountain

gen college_black = college * black
gen college_newengland = college * newengland
gen college_midatlanic = college * midatlanic
gen college_central = college * central
gen college_south = college * south
gen college_mountain = college * mountain

drop if age == -99 | age == -9
gen decade_birth = floor((year - age) / 10) * 10

forvalues i = 1953(4)1993 {
local j = 1 + (3 * (`i' - 1953) / 4)
qui tab decade_birth if year >= `i' & year <= `i' + 3, gen(decadedum)
drop decadedum1
qui foreach var of varlist decadedum* {
gen female_`var' = female * `var'
gen college_`var' = college * `var'
}

areg partisan female college female_college [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
matrix Results[`j', 2] = _b[female_college] 
matrix Results[`j' + 1, 2] = -_se[female_college] 
matrix Results[`j' + 2, 2] = e(N)

areg partisan female college female_college black newengland-mountain /*
*/ decadedum* female_black-college_mountain female_decadedum* /*
*/ college_decadedum* [aweight = final_weight] /*
*/  if year >= `i' & year <= `i' + 3, absorb(series) robust
matrix Results[`j', 3] = _b[female_college] 
matrix Results[`j' + 1, 3] = -_se[female_college] 
drop decadedum*
drop female_decadedum*
drop college_decadedum*
}

drop if missing_income == -99 | missing_income == 1 | lower_bound_income == -9
egen income_50 = median(lower_bound_income), by (series)
gen rich = .
replace rich = 0 if lower_bound_income < income_50 
replace rich = 1 if lower_bound_income >= income_50
egen income_20 = pctile(lower_bound_income), by (series) p(80)
gen rich_20 = .
replace rich_20 = 0 if lower_bound_income < income_20 
replace rich_20 = 1 if lower_bound_income >= income_20 
drop income_50 income_20

gen female_rich_20 = female * rich_20
gen female_rich = female * rich

gen college_rich_20 = college * rich_20
gen college_rich = college * rich

forvalues i = 1957(4)1993 {
local j = 1 + (3 * (`i' - 1953) / 4)
qui tab decade_birth if year >= `i' & year <= `i' + 3, gen(decadedum)
drop decadedum1
qui foreach var of varlist decadedum* {
gen female_`var' = female * `var'
gen college_`var' = college * `var'
}

areg partisan female college female_college [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
matrix Results[`j', 4] = _b[female_college] 
matrix Results[`j' + 1, 4] = -_se[female_college] 
matrix Results[`j' + 2, 4] = e(N)

areg partisan female college female_college black newengland-mountain /*
*/ decadedum* female_black-college_mountain female_decadedum* /*
*/ college_decadedum* [aweight = final_weight] /*
*/  if year >= `i' & year <= `i' + 3, absorb(series) robust
matrix Results[`j', 5] = _b[female_college] 
matrix Results[`j' + 1, 5] = -_se[female_college] 

areg partisan female college female_college black newengland-mountain /*
*/ decadedum* female_black-college_mountain female_decadedum* /*
*/ college_decadedum* rich rich_20 female_rich female_rich_20 /* 
*/ college_rich college_rich_20 [aweight = final_weight] /*
*/  if year >= `i' & year <= `i' + 3, absorb(series) robust
matrix Results[`j', 6] = _b[female_college] 
matrix Results[`j' + 1, 6] = -_se[female_college] 
drop decadedum*
drop female_decadedum*
drop college_decadedum*
}

drop if employment < 1 | employment > 3

gen fjob = 0 if employment == 2 | employment == 3
replace fjob = 1 if employment == 1
gen pjob = 0 if employment == 1 | employment == 3
replace pjob = 1 if employment == 2

drop if married < 0 | married > 1
gen marital_status = 1 if married == 1
replace marital_status = 0 if married == 0

gen female_fjob = female * fjob
gen female_pjob = female * pjob
gen female_marital_status = female * marital_status

gen college_fjob = college * fjob
gen college_pjob = college * pjob
gen college_marital_status = college * marital_status

forvalues i = 1977(4)1993 {
local j = 1 + (3 * (`i' - 1953) / 4)
qui tab decade_birth if year >= `i' & year <= `i' + 3, gen(decadedum)
drop decadedum1
qui foreach var of varlist decadedum* {
gen female_`var' = female * `var'
gen college_`var' = college * `var'
}

areg partisan female college female_college [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
matrix Results[`j', 7] = _b[female_college] 
matrix Results[`j' + 1, 7] = -_se[female_college] 
matrix Results[`j' + 2, 7] = e(N)

areg partisan female college female_college black newengland-mountain /*
*/ decadedum* female_black-college_mountain female_decadedum* /*
*/ college_decadedum* [aweight = final_weight] /*
*/  if year >= `i' & year <= `i' + 3, absorb(series) robust
matrix Results[`j', 8] = _b[female_college] 
matrix Results[`j' + 1, 8] = -_se[female_college] 

areg partisan female college female_college black newengland-mountain /*
*/ decadedum* female_black-college_mountain female_decadedum* /*
*/ college_decadedum* rich rich_20 female_rich female_rich_20 /* 
*/ college_rich college_rich_20 fjob pjob marital_status female_fjob /*
*/ female_pjob female_marital_status college_fjob college_pjob /*
*/ college_marital_status [aweight = final_weight] /*
*/  if year >= `i' & year <= `i' + 3, absorb(series) robust
matrix Results[`j', 9] = _b[female_college] 
matrix Results[`j' + 1, 9] = -_se[female_college] 
drop decadedum*
drop female_decadedum*
drop college_decadedum*
}

matlist Results

log close
